<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - AI French Teacher</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/french-theme.css') }}">
    <style>
        .auth-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 40px;
            background: white;
            border-radius: 12px;
            box-shadow: var(--shadow-hover);
        }
        .auth-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .auth-header h1 {
            color: var(--primary-color);
            margin-bottom: 10px;
        }
        .auth-form .form-group {
            margin-bottom: 20px;
        }
        .auth-form input {
            width: 100%;
            padding: 12px;
            border: 2px solid var(--border-color);
            border-radius: 8px;
            font-size: 14px;
        }
        .auth-form input:focus {
            outline: none;
            border-color: var(--primary-color);
        }
        .auth-form button {
            width: 100%;
            padding: 12px;
            background: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
        }
        .auth-form button:hover {
            background: #357ABD;
        }
        .auth-links {
            text-align: center;
            margin-top: 20px;
        }
        .error-msg {
            padding: 10px;
            background: #FFEBEE;
            color: #C62828;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
        }
        .default-account {
            background: #E3F2FD;
            padding: 15px;
            border-radius: 8px;
            margin-top: 20px;
            font-size: 13px;
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="auth-header">
            <div class="site-logo" style="justify-content: center; margin-bottom: 10px;">
                <span class="eiffel-tower">🗼</span>
                <h1 class="app-title" style="font-size: 32px;">AI French Teacher</h1>
            </div>
            <p style="color: #666;">Bienvenue! 欢迎登录</p>
        </div>

        <div id="errorMsg" class="error-msg"></div>

        <form class="auth-form" id="loginForm">
            <div class="form-group">
                <input type="text" id="username" placeholder="用户名" required>
            </div>
            <div class="form-group">
                <input type="password" id="password" placeholder="密码" required>
            </div>
            <button type="submit">登录</button>
        </form>

        <div class="auth-links">
            <p>还没有账号？ <a href="/register">立即注册</a></p>
        </div>

        <div style="margin-top: 30px; text-align: center;">
            <a href="/credits" style="color: var(--french-blue); text-decoration: none; font-size: 13px;">
                ⚜️ 致谢 / Remerciements
            </a>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', async (e) => {
            e.preventDefault();

            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const errorMsg = document.getElementById('errorMsg');

            try {
                const response = await fetch('/api/auth/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ username, password }),
                    credentials: 'include'
                });

                const result = await response.json();

                if (result.success) {
                    window.location.href = '/';
                } else {
                    errorMsg.textContent = result.error;
                    errorMsg.style.display = 'block';
                }
            } catch (error) {
                errorMsg.textContent = '登录失败：' + error.message;
                errorMsg.style.display = 'block';
            }
        });
    </script>
</body>
</html>

